package org.example.myleet.Utils;

import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SeparatorTableReader {

    private final String filePath;

    private final String separator;

    private List<String[]> lines;

    public SeparatorTableReader(String filePath, String separator) throws IOException {
        this.filePath = filePath;
        this.separator = separator;
        init();
    }

    private void init() throws IOException {
        File file = new File(filePath);
        if (!file.exists()) throw new FileNotFoundException("找不到文件，位置：" + filePath);
        BufferedReader br = new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath())));
        lines = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            lines.add(line.split(separator));
        }
    }

    public Iterator<String[]> iterator() {
        return lines.iterator();
    }
}
